//
//  PzHomeGuideView.swift
//  Pz
//
//  Created by 蓝鳍互娱 on 2024/6/26.
//

import Foundation
import UIKit
import SnapKit
class PzHomeGuideView: UIView {
    var guideIndex = 0
    let guideImgs = ["pzGuideBg_1","pzGuideBg_2","pzGuideBg_3"]
    var guideFinishBlock : (()->Void)?

    override init(frame: CGRect) {
        super.init(frame: frame)
        creatSubView()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    lazy var homeGuideImgView: UIImageView = {
        let imageView = UIImageView()
        return imageView
    }()
    func creatSubView() {
        self.addSubview(homeGuideImgView)
        homeGuideImgView.image = UIImage(named: guideImgs[guideIndex])
        homeGuideImgView.isUserInteractionEnabled = true
        homeGuideImgView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        let changeGuideTap = UITapGestureRecognizer(target: self, action: #selector(changeGuide))
        homeGuideImgView.addGestureRecognizer(changeGuideTap)
    }
    @objc func changeGuide(){
        guideIndex = guideIndex + 1
        if guideIndex > 2 {
            UserDefaults.standard.setValue("2", forKey: "pzDefFirst")
            UserDefaults.standard.synchronize()
            self.removeFromSuperview()
            guideFinishBlock?()
        }else{
            homeGuideImgView.image = UIImage(named: guideImgs[guideIndex])
        }
    }
}
